﻿using Estsh.Core.Model.EnumUtil;
using Estsh.Core.Models;
using Estsh.Core.Quartz.BaseService;
using Estsh.Core.Util;
using Estsh.Core.Wms.IRepositories;

namespace Estsh.Core.Wms.Jobs
{
    /// <summary>
    /// SAP系统将一定期间内待发运交货单信息发布到WMS用于后续捡配发货
    /// </summary>
    public class InterfaceSalesAndDeliveryPlanJob : IJobService
    {
        private readonly IInterfaceMasterRepository repository;


        public InterfaceSalesAndDeliveryPlanJob(IInterfaceMasterRepository _repository)
        {
            this.repository = _repository;

        }

        public string ExecuteService(string parameter)
        {
            try
            {
                List<SapDn> sapDns = repository.GetSalesAndDeliveryPlanInfo();
                if (sapDns.Count <= 0)
                {
                    return "没有待处理的销售发货信息！";
                }

                bool bl = repository.InsertSalesAndDeliveryPlanInfo(sapDns);
                if (bl == true)
                {
                    return "销售发货信息同步成功！";
                }
                else
                {
                    return "销售发货信息同步失败！";
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("销售发货信息同步错误！" + ex);
                return "销售发货信息同步错误！" + ex.Message;
            }
        }

    }
}
